package com.ruoyi.project.cyq.order.service.impl;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.project.cyq.order.domain.OrderGenre;
import com.ruoyi.project.cyq.order.mapper.OrderGenreMapper;
import com.ruoyi.project.cyq.order.service.IOrderGenreService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *
 */
@Service
public class IOrderGenreServiceImpl implements IOrderGenreService {
    @Autowired
    private OrderGenreMapper orderGenreMapper;

    @Override
    public List<OrderGenre> selectList() {
        List<OrderGenre> orderGenres = orderGenreMapper.selectList();
        return orderGenres;
    }

    @Override
    public OrderGenre selectByGenreId(long id) {
        OrderGenre orderGenre = orderGenreMapper.selectByGenreId(id);
        return orderGenre;
    }

    @Override
    public int UpdateById(OrderGenre orderGenre) {
        int i = orderGenreMapper.UpdateById(orderGenre);
        return i;
    }

    @Override
    public String checkGenreNameUnique(OrderGenre orderGenre) {
        String genreName = selectByGenreId(orderGenre.getGenreId()).getGenreName();
        if(orderGenre.getGenreName().equals(genreName)){
            return UserConstants.CYQ_ORDER_GENRE_NOT_UNIQUE;
        }
        Long postId = StringUtils.isNull(orderGenre.getGenreId()) ? -1L : orderGenre.getGenreId();
        System.out.println(postId);
        System.out.println(orderGenre.getGenreName());
        OrderGenre info = orderGenreMapper.checkGenreNameUnique(orderGenre.getGenreName());
        System.out.println(info);
        if (StringUtils.isNotNull(info) && info.getGenreId() != postId.longValue())
        {
            return UserConstants.CYQ_ORDER_GENRE_NOT_UNIQUE;
        }
        return UserConstants.CYQ_ORDER_GENRE_UNIQUE;

    }


    @Override
    public int insertGenre(OrderGenre orderGenre) {
        int i = orderGenreMapper.insertGenre(orderGenre);
        return i;
    }

    @Override
    public int deleteGenreByIds(long[] genreIds) {
        return 0;
    }
}
